package id.net.iconpln.bb.client.view;

import id.net.iconpln.bb.client.service.MasterRPCService;
import id.net.iconpln.bb.client.service.MasterRPCServiceAsync;
import id.net.iconpln.bb.client.service.TransportRPCService;
import id.net.iconpln.bb.client.service.TransportRPCServiceAsync;
import id.net.iconpln.bb.client.tools.ComboPembangkitPemasok;
import id.net.iconpln.bb.client.tools.ComboRakorPemasok;
import id.net.iconpln.bb.client.util.ClientModule;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.core.FastMap;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.StoreEvent;
import com.extjs.gxt.ui.client.store.StoreListener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.DateTimePropertyEditor;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.MultiField;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.TimeField;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class PageBbTransportShipment extends LayoutContainer {
	private final TransportRPCServiceAsync service = GWT.create(TransportRPCService.class);
	private final MasterRPCServiceAsync serviceMaster = GWT.create(MasterRPCService.class);
	private FormBinding formBindings;  
	private FormData formData; 
	private Grid grid, gridship;
	private ListStore storeRakor, storeJadwal, storeResult, storePengajuan, storeKapal;
	private ComboBox cboRakor, cboJadwal, cboKapal, cboPembangkit;
	private TextField pemasok, tonase, txtNoPreshipment, txtNoRakor, txtNoJadwal;
	private DateField txtTgl, txtTglEta, txtTglEtd;
	private TimeField txtEta, txtEtd;
	private TextArea txtKeterangan;
	private Button btnFilter;
	private ColumnModel cm;
	private FormPanel panel;
	
	
	  @Override  
	  protected void onRender(Element parent, int index) {  
	    super.onRender(parent, index);  
	    setLayout(new FitLayout());	    
	    initStore();
	    
	    formData = new FormData("-20"); 
	    ContentPanel cp = new ContentPanel();  
	    cp.setHeaderVisible(false);
	    cp.setFrame(true);  
	    cp.setLayout(new RowLayout(Orientation.HORIZONTAL));  
	    
	    ContentPanel p = new ContentPanel();
	    p.setHeaderVisible(false);
	    p.setLayout(new RowLayout(Orientation.VERTICAL));	   
	    
	    panel = createForm(); 
	    panel.setScrollMode(Scroll.AUTO);
	    formBindings = new FormBinding(panel, true);  
	    formBindings.setStore(storePengajuan); 
	    p.add(panel, new RowData(.99, 1));	
	    
	    ContentPanel pg = new ContentPanel();
	    pg.setHeaderVisible(false);
	    pg.setLayout(new RowLayout(Orientation.VERTICAL));	    
	  
	    grid = createGrid();  
	    grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
	    grid.addListener(Events.CellClick, new Listener<BaseEvent>() {            
            public void handleEvent(BaseEvent ge) {
            	txtNoRakor.setValue(grid.getSelectionModel().getSelectedItem().get("no_rakor"));
            	txtNoJadwal.setValue(grid.getSelectionModel().getSelectedItem().get("no_jadwal"));
            	tonase.setValue(grid.getSelectionModel().getSelectedItem().get("volume"));
            	txtTgl.setRawValue(grid.getSelectionModel().getSelectedItem().get("tanggal").toString());
            	txtTglEta.setRawValue(grid.getSelectionModel().getSelectedItem().get("tanggal_eta").toString());
            	txtTglEtd.setRawValue(grid.getSelectionModel().getSelectedItem().get("tanggal_etd").toString());    
            	txtEta.setRawValue(grid.getSelectionModel().getSelectedItem().get("jam_eta").toString());
            	txtEtd.setRawValue(grid.getSelectionModel().getSelectedItem().get("jam_eta").toString());
            	
            	Map mapParam = new FastMap();
	    		mapParam.put("id_transportir", grid.getSelectionModel().getSelectedItem().get("id_transportir").toString());
	    		serviceMaster.getMaster("KAPAL", mapParam, new AsyncCallback<List<Map>>() {
	    			public void onFailure(Throwable caught) {
	    				GWT.log(caught.getMessage(), null);
	    			}

	    			public void onSuccess(List<Map> result) {	
	    				storeKapal.removeAll();
	    				storeKapal.add(ClientModule.setListBaseModelFromListMap(result));
	    			}
				});
            }
		});
	    
	    ToolBar tbJadwal = new ToolBar();
	    tbJadwal.add(new LabelToolItem("<b>Jadwal Pengiriman</b>"));
	    tbJadwal.add(new SeparatorToolItem());
	    
	    pg.setTopComponent(tbJadwal);
	    pg.add(grid, new RowData(1, .5));
	    
	    ContentPanel ps = new ContentPanel();
	    ps.setHeaderVisible(false);
	    ps.setLayout(new FitLayout());	 
	    
	    gridship = createGridPreshipment();
	    gridship.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
	    gridship.addListener(Events.CellClick, new Listener<BaseEvent>() {            
            public void handleEvent(BaseEvent ge) {
            	txtNoPreshipment.setValue(gridship.getSelectionModel().getSelectedItem().get("no_pengajuan"));
            	txtNoRakor.setValue(gridship.getSelectionModel().getSelectedItem().get("no_rakor"));
            	txtNoJadwal.setValue(gridship.getSelectionModel().getSelectedItem().get("no_jadwal"));
            	tonase.setValue(gridship.getSelectionModel().getSelectedItem().get("volume"));
            	txtTgl.setRawValue(gridship.getSelectionModel().getSelectedItem().get("tanggal").toString());
            	txtTglEta.setRawValue(gridship.getSelectionModel().getSelectedItem().get("tanggal_eta").toString());
            	txtTglEtd.setRawValue(gridship.getSelectionModel().getSelectedItem().get("tanggal_etd").toString());    
            	txtEta.setRawValue(gridship.getSelectionModel().getSelectedItem().get("jam_eta").toString());
            	txtEtd.setRawValue(gridship.getSelectionModel().getSelectedItem().get("jam_eta").toString());
            	txtKeterangan.setRawValue(gridship.getSelectionModel().getSelectedItem().get("keterangan").toString());
            	
            	Map mapParam = new FastMap();
	    		mapParam.put("id_transportir", gridship.getSelectionModel().getSelectedItem().get("id_transportir").toString());
	    		serviceMaster.getMaster("KAPAL", mapParam, new AsyncCallback<List<Map>>() {
	    			public void onFailure(Throwable caught) {
	    				GWT.log(caught.getMessage(), null);
	    			}

	    			public void onSuccess(List<Map> result) {	
	    				storeKapal.removeAll();
	    				storeKapal.add(ClientModule.setListBaseModelFromListMap(result));
	    				if (storeKapal.getModels().size() > 0){
	    					cboKapal.setValue(storeKapal.getAt(0));
	    				}
	    			}
				});
	    		
	    		
            }
		});
	    ps.add(gridship);
	    ToolBar tbShip = new ToolBar();
	    tbShip.add(new LabelToolItem("<b>Data PreShipment</b>"));
	    tbShip.add(new SeparatorToolItem());	    
	    ps.setTopComponent(tbShip);	    
	    pg.add(ps, new RowData(1, .5));
	    
	    cp.add(p, new RowData(.4, 1));	   
	    cp.add(pg, new RowData(.6, 1));	    
	    
	    add(cp, new FitData(5));  
	  }  
	  
	  private void initStore(){
		  storeRakor = new ListStore(); 
		  storeJadwal = new ListStore(); 
		  storePengajuan = new ListStore(); 
		  storeKapal = new ListStore(); 
		  storeResult = new ListStore(); 
		  
		  storeResult.addStoreListener(new StoreListener<ModelData>(){
			  @Override
				public void storeAdd(StoreEvent<ModelData> se) {
					// TODO Auto-generated method stub
					super.storeAdd(se);
					MessageBox.alert("Information", se.getModels().get(0).get("message").toString(), null);  
				}			  
		  });
	  }
	  
	  private FormPanel createForm() {  
	    final FormPanel panel = new FormPanel();	    
	    panel.setHeaderVisible(false);
	    
	    FieldSet fieldSetFilter = new FieldSet();  
	    fieldSetFilter.setHeading("Data Filter");  
	    fieldSetFilter.setCollapsible(false);
	    
	    FormLayout layoutFilter = new FormLayout();  
	    layoutFilter.setLabelWidth(100);  
	    fieldSetFilter.setLayout(layoutFilter);  
	    
	    cboRakor = new ComboRakorPemasok(Registry.get("idPltu").toString());  
	    cboRakor.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {
	    	@Override
	    	public void selectionChanged(SelectionChangedEvent<ModelData> se) {
	    		Map map = new FastMap();
	    	    map.put("no_rakor", cboRakor.getValue().get("no_rakor").toString());
	    	    map.put("id_pemasok", Registry.get("idPltu").toString());
	    	    service.getListPengendalian("PEMBANGKIT_BY_RAKOR", map, new AsyncCallback<List<Map>>() {
	    			public void onFailure(Throwable caught) {
	    				GWT.log(caught.getMessage(), null);
	    			}

	    			public void onSuccess(List<Map> result) {	
	    				cboPembangkit.getStore().removeAll();
	    				cboPembangkit.getStore().add(ClientModule.setListBaseModelFromListMap(result));
	    			}
	    		});
	    	}
		});
	    fieldSetFilter.add(cboRakor);
	    
	    
	    cboPembangkit = new ComboPembangkitPemasok(Registry.get("idPltu").toString());
	    cboPembangkit.setWidth(200);
	    fieldSetFilter.add(cboPembangkit);
	    cboPembangkit.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {
	    	@Override
	    	public void selectionChanged(SelectionChangedEvent<ModelData> se) {
	    		getListPengajuan(cboRakor.getValue().get("no_rakor").toString(), "ENTRY", 
	    	  			  cboPembangkit.getValue().get("id_pltu").toString());	    		
	    	}
		});
	    
	    
	    
	    FormLayout layout = new FormLayout();  
	    layout.setLabelWidth(120);  
	    FieldSet fieldSet = new FieldSet();  
	    fieldSet.setHeading("Pengajuan Shipment");  
	    fieldSet.setCollapsible(false);
	    fieldSet.setLayout(layout); 
	    
	    txtNoPreshipment = new TextField();
	    txtNoPreshipment.setName("no_pengajuan");  
	    txtNoPreshipment.setFieldLabel("No Pengajuan");	 
	    txtNoPreshipment.setReadOnly(true);
	    fieldSet.add(txtNoPreshipment, formData);
	    
	    txtNoRakor = new TextField();
	    txtNoRakor.setName("no_rakor");  
	    txtNoRakor.setFieldLabel("No Rakor");	
	    fieldSet.add(txtNoRakor, formData);
	    
	    txtNoJadwal = new TextField();
	    txtNoJadwal.setName("no_jadwal");  
	    txtNoJadwal.setFieldLabel("No Jadwal");	
	    fieldSet.add(txtNoJadwal, formData);
	    
	    cboKapal = new ComboBox();  
	    cboKapal.setName("id_kapal");  
	    cboKapal.setFieldLabel("Kapal Api");
	    cboKapal.setEmptyText("Select Kapal...");  
	    cboKapal.setDisplayField("nama_kapal");  
	    cboKapal.setWidth(150);  
	    cboKapal.setStore(storeKapal);  
	    cboKapal.setTypeAhead(true);  
	    cboKapal.setTriggerAction(TriggerAction.ALL); 
	    fieldSet.add(cboKapal, formData);	  
	    
	    txtTgl = new DateField(); 
	    txtTgl.setName("tanggal");
	    txtTgl.setPropertyEditor(new DateTimePropertyEditor("dd/MM/yyyy"));
	    txtTgl.setFieldLabel("Tanggal");  
	    txtTgl.setData("text", "Enter Tanggal");     
	    txtTgl.setValue(new Date());
	    fieldSet.add(txtTgl, formData);	   
	    
	    txtTglEtd = new DateField(); 
	    txtTglEtd.setName("tanggal_etd");
	    txtTglEtd.setPropertyEditor(new DateTimePropertyEditor("dd/MM/yyyy"));
	    txtTglEtd.setFieldLabel("Tanggal ETD");  
	    txtTglEtd.setData("text", "Enter Tanggal ETD");  
	    txtTglEtd.setWidth(100);
	    
	    txtEtd = new TimeField();
	    txtEtd.setName("time_etd");
	    txtEtd.setData("text", "Enter ETD"); 
	    txtEtd.setWidth(100);
	    txtEtd.setFormat(DateTimeFormat.getFormat("HH:mm"));
	    txtEtd.setIncrement(15);
	    
	    MultiField mfPanel1 = new MultiField();
	    mfPanel1.setSpacing(10);
	    mfPanel1.setFieldLabel("ETD");
	    mfPanel1.add(txtTglEtd);
	    mfPanel1.add(txtEtd);	    
	    fieldSet.add(mfPanel1, formData);	   
	    
	    txtTglEta = new DateField(); 
	    txtTglEta.setName("tanggal_eta");
	    txtTglEta.setPropertyEditor(new DateTimePropertyEditor("dd/MM/yyyy"));
	    txtTglEta.setFieldLabel("Tanggal ETA");  
	    txtTglEta.setData("text", "Enter Tanggal ETA");    
	    txtTglEta.setWidth(100);
	    
	    txtEta = new TimeField();
	    txtEta.setName("time_eta");
	    txtEta.setFieldLabel("ETA");  
	    txtEta.setFormat(DateTimeFormat.getFormat("HH:mm"));
	    txtEta.setIncrement(15);
	    txtEta.setWidth(100);
	    
	    MultiField mfPanel2 = new MultiField();
	    mfPanel2.setSpacing(10);
	    mfPanel2.setFieldLabel("ETA");
	    mfPanel2.add(txtTglEta);
	    mfPanel2.add(txtEta);
	    fieldSet.add(mfPanel2, formData);	
	    
	    tonase = new TextField();
	    tonase.setName("volume");  
	    tonase.setFieldLabel("Vol Kirim (Ton)");	    
	    fieldSet.add(tonase, formData);

	    txtKeterangan = new TextArea();
	    txtKeterangan.setName("keterangan");  
	    txtKeterangan.setFieldLabel("Keterangan");	    
	    fieldSet.add(txtKeterangan, formData);
	    
	    panel.add(fieldSetFilter);
	    panel.add(fieldSet);  	     

	    ContentPanel p = new ContentPanel();
	    p.setHeaderVisible(false);	    
	    p.setButtonAlign(HorizontalAlignment.RIGHT);  	    
	    
	    Button btnSubmit = new Button("Submit");
	    btnSubmit.addSelectionListener(new SelectionListener<ButtonEvent>() {
			
			@Override
			public void componentSelected(ButtonEvent ce) {
				// TODO Auto-generated method stub
				Map mapParam = new FastMap();
	    		mapParam.put("eta", txtTglEta.getRawValue() + " " + txtEta.getRawValue());	    		
	    		mapParam.put("etd", txtTglEtd.getRawValue() + " " + txtEtd.getRawValue());
	    		mapParam.put("id_kapal", cboKapal.getValue().get("id_kapal"));
	    		mapParam.put("keterangan", txtKeterangan.getValue());
	    		mapParam.put("satuan", "TON");
	    		mapParam.put("status", "ENTRY");
	    		mapParam.put("tanggal", txtTgl.getRawValue());
	    		mapParam.put("volume", tonase.getRawValue());
	    		mapParam.put("no_jadwal", txtNoJadwal.getValue());
	    		mapParam.put("user", Registry.get("whoAmI").toString());
	    		mapParam.put("app_access", "WEB");
	    		
	    		mapParam.put("no_pengajuan", txtNoPreshipment.getRawValue());
	    		if (txtNoPreshipment.getRawValue().equals("")){
	    			mapParam.put("crud", "CREATE");
	    		}else{
	    			mapParam.put("crud", "UPDATE");
	    		}
	    		service.insertPengirimanBB("PENGAJUAN", mapParam,new AsyncCallback<List<Map>>() {
	    			public void onFailure(Throwable caught) {
	    				GWT.log(caught.getMessage(), null);
	    			}

	    			public void onSuccess(List<Map> result) {	
	    				storeResult.removeAll();
	    				storeResult.add(ClientModule.setListBaseModelFromListMap(result));
	    			
	    				getListPengajuan(cboRakor.getValue().get("no_rakor").toString(), "ENTRY", 
	  		    			  cboPembangkit.getValue().get("id_pltu").toString());
	    			}
	    		});
			}
		});	    
	    p.addButton(btnSubmit);  
	    
	    p.addButton(new Button("Delete", new SelectionListener<ButtonEvent>() {  
		      @Override  
		      public void componentSelected(ButtonEvent ce) {  
		    	  Map mapParam = new FastMap();
		    		mapParam.put("eta", txtTglEta.getRawValue() + " " + txtEta.getRawValue());	    		
		    		mapParam.put("etd", txtTglEtd.getRawValue() + " " + txtEtd.getRawValue());
		    		mapParam.put("id_kapal", cboKapal.getValue().get("id_kapal"));
		    		mapParam.put("keterangan", txtKeterangan.getValue());
		    		mapParam.put("satuan", "TON");
		    		mapParam.put("status", "SHIPMENT");
		    		mapParam.put("tanggal", txtTgl.getRawValue());
		    		mapParam.put("volume", tonase.getRawValue());
		    		mapParam.put("no_jadwal", txtNoJadwal.getValue());
		    		mapParam.put("user", Registry.get("whoAmI").toString());
		    		mapParam.put("app_access", "WEB");
		    		mapParam.put("no_pengajuan", txtNoPreshipment.getRawValue());
	    		  mapParam.put("crud", "DELETE");
		    	  service.insertPengirimanBB("PENGAJUAN", mapParam,new AsyncCallback<List<Map>>() {
		    			public void onFailure(Throwable caught) {
		    				GWT.log(caught.getMessage(), null);
		    			}

		    			public void onSuccess(List<Map> result) {
		    				storeResult.removeAll();
		    				storeResult.add(ClientModule.setListBaseModelFromListMap(result));
		    				
		    				getListPengajuan(cboRakor.getValue().get("no_rakor").toString(), "ENTRY", 
		  		    			  cboPembangkit.getValue().get("id_pltu").toString());
		    			}
		    	  }); 
		    	  
		    	  
		    	  panel.reset();
		      }  
		}));  
	    
	    p.addButton(new Button("Reset", new SelectionListener<ButtonEvent>() {  
		      @Override  
		      public void componentSelected(ButtonEvent ce) {  
		        panel.reset();
		      }  
	    }));  

	    panel.add(p);
	    
	    return panel;  
	  }  
	  
	  private void getListPengajuan(String no_rakor, String status, String id_pltu){
		  Map mapParam = new FastMap();
  		  mapParam.put("no_rakor", no_rakor);
  		  mapParam.put("id_pltu", id_pltu);
  		  mapParam.put("status", status);
  		  
  		  service.getListPengendalian("JADWAL", mapParam,new AsyncCallback<List<Map>>() {
  			public void onFailure(Throwable caught) {
  				GWT.log(caught.getMessage(), null);
  			}

  			public void onSuccess(List<Map> result) {	
  				storeJadwal.removeAll();
  				storeJadwal.add(ClientModule.setListBaseModelFromListMap(result));
  			}
  		  });
  		  
  		  service.getListPengiriman("PENGAJUAN", mapParam,new AsyncCallback<List<Map>>() {
  			public void onFailure(Throwable caught) {
  				GWT.log(caught.getMessage(), null);
  			}

  			public void onSuccess(List<Map> result) {	
  				storePengajuan.removeAll();
  				storePengajuan.add(ClientModule.setListBaseModelFromListMap(result));
  			}
  		});
	  }
	 
	  private Grid createGridPreshipment(){
  			List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  

		    ColumnConfig column = new ColumnConfig();	 
		    column = new ColumnConfig("no_jadwal", "No Jadwal", 150);  
		    configs.add(column);  
		    
		    column = new ColumnConfig("no_pengajuan", "No PreShipment", 150);  
		    configs.add(column); 

		    column = new ColumnConfig("bulan_tahun", "BLTH", 100);  
		    configs.add(column);  	  
		    		  
		    column = new ColumnConfig("tanggal", "Tanggal", 100);  
		    configs.add(column);
		    
		    column = new ColumnConfig("id_transportir", "Transportir", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("id_kapal", "Kapal", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("volume", "Vol (Ton)", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("eta", "ETA", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("etd", "ETD", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("status", "Status", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("keterangan", "Keterangan", 150);  
		    configs.add(column);
		    storePengajuan.setMonitorChanges(true);  
		    ColumnModel cm = new ColumnModel(configs);
		    gridship = new Grid(storePengajuan, cm);  
		    gridship.getView().setEmptyText("Data Empty");  
		    gridship.setBorders(false);  	
		    gridship.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
		    gridship.getSelectionModel().addListener(Events.SelectionChange,  
		        new Listener<SelectionChangedEvent>() {  
		          public void handleEvent(SelectionChangedEvent be) {  
		            if (be.getSelection().size() > 0) {  
		              formBindings.bind((ModelData) be.getSelection().get(0));  
		            } else {  
		              formBindings.unbind();  
		            }  
		          }  
		        });  
		    
		    return gridship;  
		  }   
	  
	  private Grid createGrid() {  
	    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  

	    ColumnConfig column = new ColumnConfig();
	    column = new ColumnConfig("no_jadwal", "No Jadwal", 150);  
	    configs.add(column);
	    
	    column = new ColumnConfig("tanggal", "Tanggal",100);  
	    configs.add(column);  
	    
	    column = new ColumnConfig("bulan_tahun", "BLTH", 100);  
	    configs.add(column);

	    column = new ColumnConfig("id_transportir", "Transportir", 100); 
	    configs.add(column);  

	    column = new ColumnConfig("volume", "Vol (Ton)", 100);  
	    configs.add(column);
	    
	    storeJadwal.setMonitorChanges(true);  
	  
	    cm = new ColumnModel(configs);  
	  
	    Grid grid = new Grid(storeJadwal, cm);  
	    grid.getView().setEmptyText("Data Empty");  
	    grid.setBorders(true);  
	  
	    return grid;  
	  }  

}
